package cn.gjxblog.validation.mvc.demo1;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Max;
import javax.validation.constraints.NotBlank;

/**
 * 完成SpringMVC中 对方法平铺参数的校验
 *
 * 两点注意
 * 1、借助Spring对方法参数校验的能力完成SpringMVC中对Controller平铺参数的校验
 * 完成自动校验需要注入一个MethodValidationPostProcessor
 *
 * 2、需要校验的接口、方法上需要@Validated注解声明
 */

@RestController
@RequestMapping
@Validated
public class UserController {

    @GetMapping("/getUserById")
    public String getUserById(@NotBlank String id){
        return "查无此人";
    }

    @GetMapping("/getUserByNameAndAge")
    public String getUserByNameAndAge(@NotBlank String name,@Max(value = 10) Integer age){
        return "查无此人";
    }
}
